package com.hopu.v1.service.front.exam.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hopu.v1.mapper.front.exam.ExamMapper;
import com.hopu.v1.pojo.common.PageData;
import com.hopu.v1.pojo.exam.ExamRecords;
import com.hopu.v1.service.front.exam.ExamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author lihao
* @description 针对表【t_exam_records(考试记录表)】的数据库操作Service实现
* @createDate 2024-09-26 20:20:39
*/
@Service
public class ExamServiceImpl extends ServiceImpl<ExamMapper, ExamRecords> implements ExamService {

    @Autowired
    private ExamMapper examRecordsMapper;

    /**
     * 查询班级下考试
     * @param page
     * @param id 班级id
     * @return
     */
    @Override
    public PageData selectStudentExam(Page<ExamRecords> page, Integer id,String studentId) {

        IPage<ExamRecords> examRecordsPage = examRecordsMapper.getList(page, id, Integer.valueOf(studentId));
        System.out.println(examRecordsPage);
        List<ExamRecords> records = examRecordsPage.getRecords();
        long total = examRecordsPage.getTotal();
        System.out.println(total);
        // PageData 返回
        PageData<ExamRecords> pageData = new PageData<>((int) page.getCurrent(), (int) page.getSize(), (int) total, records);
        return pageData;
    }

    /**
     * 查询某个试卷的信息、题目、选项
     * @param id
     * @return
     */
    @Override
    public
    ExamRecords getStudentOneExam(Integer id,String studentId) {
        return examRecordsMapper.selectByExamRecordAndAnswer(id, Integer.valueOf(studentId));
    }
}




